home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / anivga12 / example5.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-07-11  |  2.9 KB  |  91 lines

  1. {$A+,B-,D+,L+,N-,E-,O-,R-,S-,V-,G-,F-,I-,X-}
  2. {$M 16384,0,655360}
  3. PROGRAM Example5;
  4.  
  5. {Demonstrates how to use an image as a scrolling background: the program will}
  6. {load 5 tiles: a black one to be used for the surrounding image, and an image}
  7. {2x2 tiles which is used to build the real background "image"}
  8.  
  9. {$X+} {to ignore results of functions}
  10. USES ANIVGA,CRT;
  11. CONST TileName1='black.COD';     {1 black tile}
  12.       TileName2='aegypten.COD';  {4 tiles, captured from Win3.1}
  13.       tiles_per_row=2;           {These are the proportions of }
  14.       tiles_per_column=2;        {the above 4 tile file: 2x2!  }
  15.       SpriteName='flower.COD';
  16.       FlowerLoadNumber=1;        {load number for sprite}
  17.       Flower1=0;                 {sprite number}
  18.       Flower2=1;                 {another one  }
  19.       ch:Char=#0;
  20.  
  21. PROCEDURE Init;
  22. {Note that the tiles do not have to be actually loaded into memory! This}
  23. {procedure pastes just _numbers_, not tiles - they will be loaded later!}
  24. BEGIN
  25.  XTiles:=0; YTiles:=0;
  26.  SetBackgroundMode(scrolling);
  27.  SetBackgroundScrollRange(50,50,300,100);
  28.  
  29.  {paste tiles into this background, using circular enumeration 1,2,3,4,1,...}
  30.  MakeTileArea(1,tiles_per_row,tiles_per_column);
  31.  
  32.  {load sprite:}
  33.  IF loadSprite(SpriteName,FlowerLoadNumber)=0
  34.   THEN BEGIN
  35.         WRITELN('Couldn''t access file '+SpriteName+' : '+GetErrorMessage);
  36.         halt(1)
  37.        END;
  38. END;
  39.  
  40. BEGIN
  41.  Init; {set up tile organization}
  42.  InitGraph;
  43.  LoadTile(TileName1,0); {load the black tile as tile #0 = surrounding pattern}
  44.  IF Error<>Err_None
  45.   THEN BEGIN
  46.         CloseRoutines;
  47.         WRITELN('Couldn''t access file '+TileName1+' : '+GetErrorMessage);
  48.         halt(1)
  49.        END;
  50.  LoadTile(TileName2,1); {load the 4 tiles as tile #1..4 = inner picture}
  51.  IF Error<>Err_None
  52.   THEN BEGIN
  53.         CloseRoutines;
  54.         WRITELN('Couldn''t access file '+TileName2+' : '+GetErrorMessage);
  55.         halt(1)
  56.        END;
  57.  
  58.  SetCycleTime(0); {animation as fast as possible}
  59.  
  60.  SpriteN[Flower1]:=FlowerLoadNumber;
  61.  SpriteX[Flower1]:=0;
  62.  SpriteY[Flower1]:=0;
  63.  SpriteN[Flower2]:=FlowerLoadNumber;
  64.  SpriteX[Flower2]:=100;
  65.  SpriteY[Flower2]:=100;
  66.  
  67.  Animate;
  68.  REPEAT
  69.   IF Hitdetect(Flower1,Flower2) THEN BEGIN sound(1000); delay(5); nosound END;
  70.   if KeyPressed
  71.    THEN BEGIN
  72.          WHILE KeyPressed DO ch:=Upcase(ReadKey);
  73.          CASE ch OF
  74.           'I':dec(SpriteY[Flower1]);  {change position of sprite with I,J,K,M}
  75.           'J':dec(SpriteX[Flower1]);
  76.           'K':inc(SpriteX[Flower1]);
  77.           'M':inc(SpriteY[Flower1]);
  78.           'E':dec(StartVirtualY,10);  {change position of whole scene with}
  79.           'S':dec(StartVirtualX,10);  {E,S,D,X}
  80.           'D':inc(StartVirtualX,10);
  81.           'X':inc(StartVirtualY,10);
  82.          END;
  83.          IF POS(ch,'IJKMESDX')>0 THEN Animate; {=only if something changed}
  84.         END;
  85.  
  86.  UNTIL (ch='Q') OR (ch=#27);  {"Q" or ESC to quit}
  87.  
  88.  CloseRoutines;
  89.  
  90. END.
  91.